package com.hsh.maoduo.util;

import com.hsh.maoduo.pojo.other.yt.MTExport;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Field;

@Slf4j
public class ClassUtil {
    /**
     * 获得某个对象某个字段的值
     * @param t 对象
     * @param fileName 字段名
     * @return 值
     * @param <T> 泛型
     */
    public static  <T> Object getFiled(T t, String fileName) {
        Object value = null;
        Class<?> tClass = t.getClass();
        try {
            Field field = tClass.getDeclaredField(fileName);
            field.setAccessible(true);
            value = field.get(t);
        } catch (Exception e) {
            log.error(e.toString());
        }
        return value;
    }

    public static void main(String[] args) {
        MTExport mtExport = new MTExport();
        mtExport.setNum(1);
        Object num = ClassUtil.getFiled(mtExport, "num");
    }
}
